<?php
mysql_connect("127.0.0.1","root","sd2013");
mysql_select_db("mathRomp");

//Update user's score in the game
$q1=mysql_query("UPDATE `Games-Users` SET `userScore`=`userScore`+".$_REQUEST['increment']." WHERE gameId=".$_REQUEST['gameId']." AND userId=".$_REQUEST['userId']."");
while($g=mysql_fetch_assoc($q1)){
  $output1[]=$g;
}
print(json_encode($output1));

//Update user's total score
$q2=mysql_query("UPDATE `Users` SET totalScore = totalScore+".$_REQUEST['increment']." WHERE userId = ".$_REQUEST['userId']."");
while($e=mysql_fetch_assoc($q2)){
  $output2[]=$e;
}
print(json_encode($output2));

//Update turn
$q3=mysql_query("UPDATE `Game` SET turn = (SELECT `userId` FROM `Games-Users` WHERE gameId = ".$_REQUEST['gameId']." AND userId != ".$_REQUEST['userId'].") WHERE gameId = ".$_REQUEST['gameId']."");
while($f=mysql_fetch_assoc($q3)){
  $output3[]=$f;
}
print("turn being updated");
print(json_encode($output3));

?>